﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components.sunface {
    import flash.display.*;
    import net.wooga.pets.views.components.sunface.states.*;
    import __AS3__.vec.*;
    import net.wooga.pets.utils.timeline.*;
    import net.wooga.pets.constants.*;

    public class SunFaceStateManager implements ISunFaceState {

        private var _statesLookupTable:Vector.<ISunFaceState>;
        private var _currentState:ISunFaceState;
        private var _hourlyBasedState:int;
        private var _timeStateBasedChanged:Boolean;
        private var _fixedState:Boolean;
        private var _isTalking:Boolean;

        public static const NULL_STATE:uint = 0;
        public static const NIGHT_STATE:uint = 1;
        public static const DAWN_STATE:uint = 2;
        public static const DAY_STATE:uint = 3;
        public static const DAYTIME_TALKING:uint = 4;
        public static const NIGHTTIME_TALKING:uint = 5;
        public static const DAYTIME_CLICK:uint = 6;
        public static const NIGHTTIME_CLICK:uint = 7;

        public function initialize(_arg1:MovieClip):void{
            var _local2:SequenceBasedStatesTimeline = new SequenceBasedStatesTimeline(_arg1);
            this._statesLookupTable = new Vector.<ISunFaceState>();
            this._statesLookupTable[NULL_STATE] = new SunFaceNullState(this, _local2);
            this._statesLookupTable[NIGHT_STATE] = new SunFaceNighttime(this, _local2);
            this._statesLookupTable[DAWN_STATE] = new SunFaceDawntime(this, _local2);
            this._statesLookupTable[DAY_STATE] = new SunFaceDaytime(this, _local2);
            this._statesLookupTable[DAYTIME_TALKING] = new SunFaceTalking(this, _local2);
            this._statesLookupTable[NIGHTTIME_TALKING] = new SunFaceNightTalking(this, _local2);
            this._statesLookupTable[DAYTIME_CLICK] = new SunFaceDayClick(this, _local2);
            this._statesLookupTable[NIGHTTIME_CLICK] = new SunFaceNightClickState(this, _local2);
            this.forceTimeBasedStateUpdate();
            this.initiate();
        }
        private function forceTimeBasedStateUpdate():void{
            var _local1:int = new Date().hours;
            this.updateTimeBaseDefaultState(_local1);
            this._currentState = this.defaultState;
        }
        public function disableStateUpdates():void{
            this._fixedState = true;
        }
        public function enableStateUpdates():void{
            if (this._fixedState){
                this._fixedState = false;
                if (this.timebaseStateNeedsUpdating()){
                    this.currentState = this.defaultState;
                };
            };
        }
        public function initiate():void{
            this._isTalking = false;
            this._currentState.initiate();
        }
        public function destroy():void{
            var _local1:ISunFaceState;
            for each (_local1 in this._statesLookupTable) {
                _local1.destroy();
            };
            this._statesLookupTable = null;
            this._currentState = null;
        }
        public function talk():void{
            this._isTalking = true;
            this._currentState.talk();
        }
        public function idle():void{
            this._currentState.idle();
        }
        public function click():void{
            this._currentState.click();
        }
        public function stop():void{
            this._currentState.stop();
        }
        public function get isPlaying():Boolean{
            return (this._currentState.isPlaying);
        }
        public function isTalking():Boolean{
            return (this._isTalking);
        }
        public function getStateByLookupKey(_arg1:int):ISunFaceState{
            return ((this._statesLookupTable[_arg1] as ISunFaceState));
        }
        public function get defaultState():ISunFaceState{
            return ((this._statesLookupTable[this._hourlyBasedState] as ISunFaceState));
        }
        public function get currentState():ISunFaceState{
            return (this._currentState);
        }
        public function set currentState(_arg1:ISunFaceState):void{
            this._currentState = _arg1;
            this.initiate();
        }
        public function updateTimeBaseDefaultState(_arg1:Number):void{
            var _local2:int = this._hourlyBasedState;
            if ((((_arg1 >= TimeConstants.MIDNIGHT_0_OCLOCK)) && ((_arg1 < TimeConstants.DAWN_5_OCLOCK)))){
                this._hourlyBasedState = NIGHT_STATE;
            } else {
                if ((((_arg1 >= TimeConstants.DAWN_5_OCLOCK)) && ((_arg1 < TimeConstants.SUNRISE_8_OCLOCK)))){
                    this._hourlyBasedState = DAWN_STATE;
                } else {
                    if (_arg1 >= TimeConstants.SUNRISE_8_OCLOCK){
                        this._hourlyBasedState = DAY_STATE;
                    };
                };
            };
            this._timeStateBasedChanged = !((_local2 == this._hourlyBasedState));
        }
        public function timebaseStateNeedsUpdating():Boolean{
            if (this._fixedState == true){
                return (false);
            };
            return (this._timeStateBasedChanged);
        }

    }
}//package net.wooga.pets.views.components.sunface 
